package com.bishe.admin.service.serviceImpl;

import com.bishe.admin.entity.User;
import com.bishe.admin.mapper.LoginMapper;
import com.bishe.admin.service.LoginService;
import com.bishe.admin.entity.UserDto;

import com.bishe.common.utils.SaltMD5Util;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


@Service
@RequiredArgsConstructor
public class LoginServiceImpl implements LoginService {
    private final LoginMapper loginMapper;
    @Override
    public User login(User user) {

        try {
            User login = loginMapper.Login(user);
            if (SaltMD5Util.verifySaltPassword(user.getPassword(), login.getPassword())) {
                return login;
            }
        } catch (Exception e) {
            return null;
        }

        return null;
    }

    @Override
    public boolean Registered(UserDto user) {
        user.setPassword(SaltMD5Util.generateSaltPassword(user.getPassword()));
        return loginMapper.Registered(user);
    }
}
